<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    :modal="true"
    :appendToBody="true"
    width="60%"
    v-dialog-drag
    :close-on-click-modal="false"
    top="6vh"
    @close="handleClose()"
    @open="handleOpen()"
  >
    <el-form :model="form" :rules="rules" ref="ruleForm" :disabled='mode == "look"' label-width="110px">
      <PartitionTitle title="规则基础信息"></PartitionTitle>
      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="规则编码" prop="ruleNo" key='ruleNo'>
            <el-input type="text" v-model="form.ruleNo" placeholder="请输入规则编码" :disabled="!!(row && row.id)"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-switch
            v-model="systemNo"
            active-text="系统编号"
            class="system-num"
            @change="handleGetCode"
            :disabled="!!(row && row.id)"
          >
          </el-switch>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="关联指标" prop="indexCode" key='indexCode'>
            <el-input type="text" v-model="form.indexName" placeholder="请选择关联指标" readonly :disabled="!!(row && row.id)">
              <el-button slot="append" icon="el-icon-search" @click="openIndexDialog" readonly :disabled="!!(row && row.id)"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <template v-if='form.indexCode'>
        <el-row type="flex" justify="space-between">
          <el-col :span="12" v-if='form.indexOrganization'>
            <el-form-item label="指标组织维度" prop='indexOrganization' key='indexOrganization'>
              <el-input type="text" v-model="form.indexOrganization" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12" v-if='form.indexType'>
            <el-form-item label="指标类型" prop="indexType" key='indexType'>
              <el-input type="text" v-model="form.indexTypeName" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex" justify="space-between">
          <el-col :span="12" v-if='form.factoryDeptName'>
            <el-form-item label="所属工厂" prop='factoryDeptName' key='factoryDeptName'>
              <el-input type="text" v-model="form.factoryDeptName" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12" v-if='form.workshopName' key='workshopName'>
            <el-form-item label="所属车间" prop='workshopName'>
              <el-input type="text" v-model="form.workshopName" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex" justify="space-between">
          <el-col :span="12" v-if='form.lineName'>
            <el-form-item label="所属产线" prop='lineName' key='lineName'>
              <el-input type="text" v-model="form.lineName" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12" v-if='form.equipmentName'>
            <el-form-item label="关联设备" prop='equipmentName' key='equipmentName'>
              <el-input type="text" v-model="form.equipmentName" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex" justify="space-between" v-if='form.lineName'>
          <el-col :span="12">
            <el-form-item label="适用工艺路线" :prop="form.lineName? 'processRouteIds' : ''" key='processRouteIds'>
              <el-input type="text" v-model="form.processRouteNames" placeholder="请选择适用工艺路线" class="input-with-select" readonly>
               <el-select v-model="form.processAll" slot="prepend" placeholder="请选择" @change="selectAll">
                 <el-option
                  v-for="item in proList"
                  :label="item.label"
                  :value="item.key"
                  :key="item.key"
                  >
                  </el-option>
               </el-select>
                <el-button slot="append" icon="el-icon-search" @click="openProcessDialog" readonly :disabled="form.processAll == 1"></el-button>
              </el-input>
              <el-button type="text">若选择全部,则后续新增工艺路线自动关联</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </template>

      <PartitionTitle title="规则设置"></PartitionTitle>
      <el-row type="flex" align='middle'>
        <el-col :span="8">
          <el-form-item prop="abnormalMin" label="异常区间" key='abnormalMin'>
            <el-input-number v-model="form.abnormalMin" placeholder="请输入下限"></el-input-number>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item prop="abnormalMax" class='no-ml' key='abnormalMax'>
            <el-input-number v-model="form.abnormalMax" placeholder="请输入上限"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="4" class='no-ml'>
          <el-form-item prop='abnormalUnit' key='abnormalUnit'>
            <div>单位：<span>{{form.abnormalUnit}}</span></div>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex" justify="space-between">
        <el-col :span="12">
          <el-form-item label="异常等级" prop="abnormalLevelCode" key='abnormalLevelCode'>
            <el-select
              placeholder="请选择异常等级"
              clearable
              v-model="form.abnormalLevelCode"
              size="small"
            >
              <el-option
                v-for="item in dict.AbnormalLevel"
                :key="item.codevalue"
                :label="item.codename"
                :value="item.codevalue"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="8">
          <el-form-item label="预警区间" prop='warmMin' key='warmMin'>
            <el-input-number v-model="form.warmMin" placeholder="请输入下限"></el-input-number>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item  class='no-ml' prop='warmMax' key='warmMax'>
            <el-input-number v-model="form.warmMax" placeholder="请输入上限"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="4" class='no-ml'>
          <el-form-item prop='warmUnit' key='warmUnit'>
            <div>单位：<span>{{form.warmUnit}}</span></div>
          </el-form-item>
        </el-col>
      </el-row>

      <PartitionTitle title="责任人设置"></PartitionTitle>

      <el-row type="flex" justify="space-between">
        <el-col :span="12">
          <el-form-item prop="processedNames" label="责任人" key='processedNames'>
            <el-input type="text" v-model="form.processedNames" placeholder="请选择人员" readonly>
              <el-button slot="append" icon="el-icon-search" @click="openUserDialog"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <template v-if='form.erpProductionLineCode'>
        <el-row type="flex" justify="space-between">
          <el-col :span="12">
            <el-form-item prop="processedPost" key='processedPost'>
              <el-select
                placeholder="请选择岗位"
                clearable
                v-model="form.processedPost"
                size="small"
                @change='selectPost'
              >
                <el-option
                  v-for="item in dict.PostManage"
                  :key="item.codevalue"
                  :label="item.codename"
                  :value="item.codevalue"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex" justify="space-between">
          <el-col :span="12">
            <el-form-item prop="workStationId" key='workStationId'>
              <el-input type="text" v-model="form.workStationName" placeholder="请选择工位" readonly>
                <el-button slot="append" icon="el-icon-search" @click="openStationDialog"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </template>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" :loading="saveloading" @click="handleSubmit" v-if='mode != "look"'>确 定</el-button>
    </span>

    <userList
      :visibles.sync="userDialog.visible"
      :multiple="true"
      :defaultValues="userDialog.defaulSelectUsers"
      :branchinnercode="userDialog.branchinnercode"
      @closeDialog="closeUserDialog"
    >
  </userList>

  <index-List
    :visible.sync="indexDialog.visible"
    :defaultValues="indexDialog.defaultValues"
    :defaultSearch="{
      factoryDeptCode: form.factoryDeptCode,
      workshopId: form.workshopId,
      workshopCode: form.workshopCode,
      lineId: form.lineId,
    }"
    :multiple="false"
    @closeDialog="closeIndexDialog"
  />

  <process-route-list
    :visible.sync="processRouteDialog.visible"
    :multiple="true"
    :defaultValues="processRouteDialog.defaultValues"
    :disabledSearch="{
      factory: true,
      workshop: true,
      line: true,
      searchValue: false,
    }"
    :defaultSearch="{
      factoryDeptCode: form.factoryDeptCode,
      factoryDeptId:form.factoryDeptId,
      workshopId: form.workshopId,
      workshopCode: form.workshopCode,
      lineId: form.lineId,
    }"
    :isResetQuery="false"
    @closeDialog="closeProcessDialog"
  />
  <stationList
    :visibles.sync="stationDialog.visible"
    :disabledData="disabledData"
    :defaultValues="stationDialog.selectStationList"
    :arrData="{
      factoryDeptCode: form.factoryDeptCode,
      workshopCode: form.workshopCode,
      lineId: form.lineId
    }"
    :isResetQuery="false"
    :multiple="false"
    @closeDialog="closeStationDialog">
  </stationList>
  </el-dialog>
</template>
<script>
  import IndexList from "@/views/components/indexList";
  import ProcessRouteList from "@/views/components/processRouteList";
  import stationList from "@/views/components/stationList";
  import {validLetterDigit,patterns} from "@/utils/validate";
  import {abnormalNo,ruleDetail,addOrUpdateRule} from "@/api/exceptionMgmt/rule";
  import {getIndexConfigDetail} from "@/api/indexMgmt/configuration";
  import {getProcessRouteList} from "@/api/processRouteMgmt/maintenance";
  import { mapState,mapGetters } from "vuex";
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default: null
    },
    mode:{
      type: String,
      default: null
    },
    title:{
      type: String,
      default: null
    }
  },
  dicts: ["indexBizOrgDimension", "indexType", "AbnormalType", "AbnormalLevel", "PostManage"],
  data() {
    const validUnusual = (rule,value, callback) => {
      if(this.form.abnormalMin == undefined && this.form.abnormalMax == undefined){
        return callback(new Error("异常区间上限、下限至少填写一个"));
      }else if(this.form.abnormalMin!= undefined && this.form.abnormalMax!= undefined){
        if(this.form.abnormalMin > this.form.abnormalMax){
          return callback(new Error("异常区间下限不能大于上限"));
        }else{
          this.$refs.ruleForm.clearValidate(['abnormalMax','abnormalMin'])
          callback();
        }
      }
      else{
        this.$refs.ruleForm.clearValidate(['abnormalMax','abnormalMin'])
        callback();
      }
    };

    const validWarn = (rule,value, callback) => {
      if(this.form.warmMin!= undefined && this.form.warmMax!= undefined){
        if(this.form.warmMin > this.form.warmMax){
          return callback(new Error("预警区间下限不能大于上限"));
        }else{
          this.$refs.ruleForm.clearValidate(['warmMax','warmMin'])
          callback();
        }
      }else{
        this.$refs.ruleForm.clearValidate(['warmMax','warmMin'])
        callback();
      }
    };

    const validLeader = (rule,value, callback) => {
      if(!this.form.workStationId && !this.form.processedPost && !this.form.processedNames){
        return callback(new Error("请选择责任人"));
      }else{
        this.$refs.ruleForm.clearValidate(['workStationId','processedPost','processedNames'])
        callback();
      }
    };

    const validProcess = (rule,value, callback) => {
      if(!this.form.processRouteIds?.length && this.form.processAll != 1){
        return callback(new Error("请选择适用工艺路线"));
      }else{
        callback();
      }
    };
    return {
      form: {
        ruleNo: null,
        indexCode:null,
        indexName:null,
        indexType:null,
        indexTypeName:null,
        indexOrganization:null,
        factoryDeptCode: null,
        factoryDeptId:null,
        factoryDeptName:null,
        workshopCode: null,
        workshopId:null,
        workshopName:null,
        erpProductionLineCode:null,
        lineId:null,
        lineName:null,
        equipmentCode:null,
        equipmentName:null,
        abnormalLevelCode:null,
        processAll:"0",
        processRouteIds:[],
        processRouteNames:null,
        abnormalMin:undefined,
        abnormalMax:undefined,
        warmMin:undefined,
        warmMax:undefined,
        abnormalUnit:null,
        warmUnit:null,
        workStationId:null,
        workStationName:null,
        processedPost:null,
        processedUserName:null,
        processedNames:null,    //人员
        processedName:null
      },
      indexList:[],
      systemNo:false,
      rules: {
        ruleNo: [
          { required: true, message: "请输入规则编码" },
          { pattern: patterns.letterDigit, message: "班次类型编码只能是字母和数字", trigger: 'blur' },
          { max: 32, message: "不能超过32个字符", trigger: "blur" },
        ],
        indexCode: [
          { required: true, message: "请选择关联指标", trigger: "change" },
        ],
        processRouteIds:[
          { required: true, validator: validProcess, trigger: "change" },
        ],
        abnormalMin:[
          {required: true,validator: validUnusual, trigger: ['blur', 'change'] }
        ],
        abnormalMax:[
          {required: true,validator: validUnusual, trigger: ['blur', 'change'] }
        ],
        warmMin:[
          {validator: validWarn, trigger: ['blur', 'change'] }
        ],
        warmMax:[
          {validator: validWarn, trigger: ['blur', 'change'] }
        ],
        abnormalLevelCode: [
          { required: true, message: "请选择异常等级", trigger: "change" },
        ],
        processedPost:[
          {required: true, validator: validLeader, trigger: "change" },
        ],
        workStationId:[
          {required: true, validator: validLeader, trigger: "change" },
        ],
        processedNames:[
          {required: true, validator: validLeader, trigger: "change" }
        ]
      },
      userDialog: {
        visible: false,
        branchinnercode:null,
        defaulSelectUsers:[]
      },
      indexDialog: {
        visible: false,
        defaultValues: [],
      },
      processRouteDialog: {
        defaultValues:[],
        visible: false,
      },
      disabledData:{
        factory:true,
        workshop:true,
        line:true
      },
      stationDialog:{
        arrData:{},             //过滤条件
        visible: false,
        selectStationList:[]
      },
      disabledUser:[],
      pager: {
        total: 0,
        pageNum: 1,
        pageSize: 10
      },
      proList:[
        {label:"全部",key:"1"},
        {label:"部分",key:"0"}
      ],
      selectableUserCallBack: (row) => {
        return !this.disabledUser.includes(row.username)
      },
      saveloading: false
    };
  },
  computed: {
    dialogVisible: {
      set(val) {
        this.$emit("update:visible", val)
      },
      get() {
        return this.visible
      }
    },
    ...mapState({
      allList:(state) => state.common.allList,
      permitList:(state) => state.common.permitList,
    }),
    ...mapGetters([
      'baseDeptId',
      "permitList",
      "allList"
    ]),
    bizOrgDimensionDictMap() {
      return this.dictToMap(this.dict.indexBizOrgDimension);
    },
    indexTypeDictMap() {
      return this.dictToMap(this.dict.indexType);
    }
  },

  created(){
  },

  methods: {
    handleClose() {
      this.saveloading = false;
      this.systemNo = false;
      this.resetFormData()
    },
    handleOpen() {
      const reg = /^(\-|\+)?\d+(\.\d+)?$/;
      if (!this.row?.id) {
        this.resetFormData();
        return
      }
      this.form = Object.assign({},this.row);
      if(this.form.processedUserName){//人员
        this.form.processedNames = this.form.processedName;
      }
      if(this.form.workStationId){//工位
        this.form.workStationName = this.form.processedName;
      }

      if(this.form.abnormalMin == null || !reg.test(Number(this.form.abnormalMin))){
        this.form.abnormalMin = undefined
      }
      if(this.form.abnormalMax == null|| !reg.test(Number(this.form.abnormalMax))){
        this.form.abnormalMax = undefined
      }
      if(this.form.warmMin == null|| !reg.test(Number(this.form.warmMin))){
        this.form.warmMin = undefined
      }
      if(this.form.warmMax == null|| !reg.test(Number(this.form.warmMax))){
        this.form.warmMax = undefined
      }
      // this.form.processAll = this.form.processAll+'';
      if(this.form?.indexCode){
        this.getIndexDetail()
      }
    },

    getProcessList() {
      const { factoryDeptId, workshopId, lineId } = this.form;
      const params = {
        query: {
          factoryDeptId,
          workshopId,
          lineId,
        },
        pageNum:1,
        pageSize:500
      };
      getProcessRouteList(params)
      .then((res) => {
        if(res.code == 200 && res.rows){
          const list = res.rows;
          if(list?.length){
            this.$nextTick(()=>{
              let processRouteNames = ''
              list.forEach(item => {
                if(!!this.form.processRouteIds.includes(item.id)){
                  processRouteNames += item.processRouteName
                }
              })
              this.$set(this.form,"processRouteNames",processRouteNames)
            })
          }
          // this.form.processRouteNames = processRouteNames.join()
        }
      })
    },

    getIndexDetail(){
      getIndexConfigDetail(this.form?.indexCode)
      .then(res=>{
        if (res.code == 200 && res.data) {
          const indexItem = res.data;
          const {indexType,bizOrgDimension,indexUnit} = indexItem?.indexMetaDto;
          const {factoryDeptName,workshopName,indexConfigName,
            lineName,factoryDeptCode,factoryDeptId,
            workshopCode,workshopId,lineCode,
            lineId,equipCode,equipName,id
          } = indexItem;
          this.form.indexCode = id;
          this.form.indexName = indexConfigName;
          this.form.indexType = indexType;
          this.$nextTick(()=>{
            this.form.indexTypeName = indexType ? this.indexTypeDictMap[indexType] : null;
            this.form.indexOrganization = bizOrgDimension ? this.bizOrgDimensionDictMap[bizOrgDimension] : null;
            this.$forceUpdate()
          })
          this.form.abnormalUnit = indexUnit;
          this.form.warmUnit = indexUnit;
          this.form.factoryDeptName = factoryDeptName;
          this.form.factoryDeptCode = factoryDeptCode;
          this.form.factoryDeptId = factoryDeptId;
          this.form.workshopName = workshopName;
          this.form.workshopCode = workshopCode;
          this.form.workshopId = workshopId;
          this.form.lineName = lineName;
          this.form.lineId = lineId;
          this.form.erpProductionLineCode = lineCode;
          this.form.equipmentCode = equipCode;
          this.form.equipmentName = equipName;
          if(this.form?.lineId && this.form?.processAll != 1){
            this.getProcessList()
          }
        } else {
          this.resetFormData()
        }
      }).catch(() => {
        this.resetFormData()
      })
    },

    handleSubmit() {
      if(this.mode == "look"){
        this.dialogVisible = false;
        return
      }
      this.saveloading = true
      this.$refs.ruleForm
      .validate((flag) => {
        if (flag) {
          let parmas = {
            id:this.form.id,
            ruleNo: this.form.ruleNo,
            indexCode:this.form.indexCode,
            indexType:this.form.indexType,
            indexOrganization:this.form.indexOrganization,
            factoryDeptCode: this.form.factoryDeptCode,
            factoryDeptId: this.form.factoryDeptId,
            workshopCode: this.form.workshopCode,
            erpProductionLineCode:this.form.erpProductionLineCode,
            equipmentCode:this.form.equipmentCode,
            processRouteIds:this.form.processRouteIds,
            processAll:this.form.processAll,
            abnormalLevelCode:this.form.abnormalLevelCode,
            abnormalMin:this.form.abnormalMin,
            abnormalMax:this.form.abnormalMax,
            warmMin:this.form.warmMin,
            warmMax:this.form.warmMax,
            abnormalUnit:this.form.abnormalUnit,
            warmUnit:this.form.warmUnit,
            workStationId:this.form.workStationId,
            processedPost:this.form.processedPost,
            processedUserName:this.form.processedUserName
          }
          addOrUpdateRule(parmas).then(res => {
            if (res.code == 200) {
              this.msgSuccess("操作成功")
              this.$emit("submit-success")
              this.dialogVisible = false
            } else {
              this.msgError(res.msg || "操作失败")
            }
            this.saveloading = false
          }).catch(() => {
            this.msgError("操作失败")
            this.saveloading = false
          })
        } else {
          this.saveloading = false
        }
      })
    },

    //选择岗位
    selectPost(val){
      this.form.workStationId = null;
      this.form.workStationName = null;
      this.form.processedNames = null;
      this.form.processedUserName = null;
    },

    //选择工位
    openStationDialog(){
      this.stationDialog.selectStationList = [];
      if(this.form.workStationId){
        this.stationDialog.selectStationList.push({
          workStationId:this.form.workStationId,
          workStationName:this.form.workStationName
        })
      }
      this.stationDialog.visible = true
    },

    //确定选择工位
    closeStationDialog(list){
      if(list?.length){
        this.form.workStationId = list.map(item => item.workStationId).join();
        this.form.workStationName = list.map(item => item.workStationName).join();
        this.form.processedPost = null;
        this.form.processedNames = null;
        this.form.processedUserName = null;
      }else{
        this.form.workStationId = null;
        this.form.workStationName = null;
      }
    },

    //打开人员选择器
    openUserDialog() {
      this.userDialog.defaulSelectUsers = [];
      this.userDialog.branchinnercode = this.baseDeptId;
      let processedUserList = this.form.processedUserName && this.form.processedUserName.split(",");
      let processedNameList = this.form.processedNames && this.form.processedNames.split(",");
      if(processedUserList?.length){
        processedUserList.forEach((item,index) => {
          this.userDialog.defaulSelectUsers.push({
            username:item,
            realname:processedNameList[index]
          })
        })
      }
      this.userDialog.visible = true
    },

    closeUserDialog(list){
      if(list?.length){
        this.form.processedUserName = list.map(item => item.username).join();
        this.form.processedNames = list.map(item => item.realname).join();
        this.form.workStationId = null;
        this.form.workStationName = null;
        this.form.processedPost = null;
      }else{
        this.form.processedUserName = "";
        this.form.processedNames = "";
      }
    },

    //选择工艺路线
    openProcessDialog(){
      if(this.form.processAll == 1){
        return
      }
      this.processRouteDialog.defaultValues = [];
      let processRouteNames = this.form?.processRouteNames?.split(",") || []
      if(this.form?.processRouteIds?.length){
        this.form.processRouteIds.forEach((item,index) => {
          this.processRouteDialog.defaultValues.push({
            id:item,
            processRouteName:processRouteNames[index]
          })
        })
      }
      this.processRouteDialog.visible = true;
    },

    closeProcessDialog(list){
      if(list?.length){
        this.form.processRouteIds = list.map(item => item.id);
        this.form.processRouteNames = list.map(item => item.processRouteName).join();
      }else{
        this.form.processRouteIds = [];
        this.form.processRouteNames = null;
      }
    },

    openIndexDialog() {
      this.indexDialog.defaultValues = [];
      if(this.form.indexCode){
        this.indexDialog.defaultValues.push({
          id:this.form.indexCode,
          indexConfigName:this.form.indexName
        })
      }
      this.indexDialog.visible = true
    },

    closeIndexDialog(list) {
      if(list?.length){
        // this.form.indexCode = list.map(item => item.id).join();
        // this.form.indexName = list.map(item => item.indexConfigName).join();
        this.selectIndex(list[0])
      }else{
        this.form.indexCode = null
        this.form.indexName = null;
        this.form.indexType = null;
        this.form.abnormalUnit = null;
        this.form.warmUnit = null;
        this.form.indexOrganization = null;
        this.form.factoryDeptName = null;
        this.form.factoryDeptCode = null;
        this.form.factoryDeptId = null;
        this.form.workshopName = null;
        this.form.workshopCode = null;
        this.form.workshopId = null;
        this.form.lineName = null;
        this.form.lineId = null;
        this.form.erpProductionLineCode = null;
        this.form.equipmentCode = null;
        this.form.equipmentName = null;
      }
    },

    //选择关联指标
    selectIndex(indexItem){
      const {indexType,bizOrgDimension,indexUnit} = indexItem?.indexMetaDto;
      const {factoryDeptName,
          workshopName,
          lineName,
          factoryDeptCode,
          factoryDeptId,
          workshopCode,
          workshopId,
          lineCode,
          lineId,
          equipCode,
          equipName,
          id,
          indexConfigName
      } = indexItem;
      this.form.indexCode = id;
      this.form.indexName = indexConfigName;
      this.form.indexType = indexType;
      this.form.indexTypeName = indexType ? this.indexTypeDictMap[indexType] : null;
      this.form.abnormalUnit = indexUnit;
      this.form.warmUnit = indexUnit;
      this.form.indexOrganization = bizOrgDimension ? this.bizOrgDimensionDictMap[bizOrgDimension] : null;
      this.form.factoryDeptName = factoryDeptName;
      this.form.factoryDeptCode = factoryDeptCode;
      this.form.factoryDeptId = factoryDeptId;
      this.form.workshopName = workshopName;
      this.form.workshopCode = workshopCode;
      this.form.workshopId = workshopId;
      this.form.lineName = lineName;
      this.form.lineId = lineId;
      this.form.erpProductionLineCode = lineCode;
      this.form.equipmentCode = equipCode;
      this.form.equipmentName = equipName;
    },

    //获取系统编码
    handleGetCode(value) {
      if (value == true) {
        abnormalNo().then((res) => {
          if (res.code == 200) {
            this.form.ruleNo = res.data || null;
          }
        });
      }
    },

    selectAll(val){
      this.form.processAll = val;
      this.form.processRouteIds = [];
      this.form.processRouteNames = null;
    },

    resetFormData() {
      this.$refs.ruleForm?.resetFields()
      this.form = {
       ruleNo: null,
       indexCode:null,
       indexName:null,
       indexType:null,
       indexTypeName:null,
       indexOrganization:null,
       factoryDeptCode: null,
       factoryDeptId:null,
       factoryDeptName:null,
       workshopCode: null,
       workshopId:null,
       workshopName:null,
       erpProductionLineCode:null,
       lineId:null,
       lineName:null,
       equipmentCode:null,
       equipmentName:null,
       abnormalLevelCode:null,
       processAll:"0",
       processRouteIds:[],
       processRouteNames:null,
       abnormalMin:undefined,
       abnormalMax:undefined,
       warmMin:undefined,
       warmMax:undefined,
       abnormalUnit:null,
       warmUnit:null,
       workStationId:null,
       workStationName:null,
       processedPost:null,
       processedUserName:null,
       processedNames:null,    //人员
       processedName:null
      };
    },
  },

  components:{
    IndexList,
    ProcessRouteList,
    stationList
  }
};
</script>
<style lang="scss" scoped>
.el-form {
  // display: flex;
  // justify-content: space-between;
  // flex-flow: wrap;
  // .el-form-item {
  //   width: 49%;
  // }
  .no-ml{
    ::v-deep .el-form-item__content{
      margin-left:16px !important
    }
  }
  .el-date-editor.el-input,
  .el-select {
    width: 100%;
  }
  .input-with-select{
    .el-select {
      width: 90px;
    }
  }
  .el-input-number{
    width: 100%;
  }
  .el-switch{
    height: 36px;
    margin-left: 20px;
  }
}
</style>
